package cn.easyutil.veteran.core.entity;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

public class CommonPage extends BaseEntity {

    private Integer showCount = 10; // 每页显示记录数

    private Integer totalPage = 0; // 总页数

    private Integer totalResult = 0; // 总记录数

    private Integer currentPage = 1; // 当前页

    /**
     * 转换成mybatisPlus需要的page对象
     */
    public Page<?> parseToMp(){
        return new Page<>(currentPage, showCount);
    }

    /**
     * 将mybatisPlus的分页转换成系统分页对象
     */
    public static CommonPage resolveMp(Page<?> page){
        CommonPage commonPage = new CommonPage();
        if(page == null){
            return commonPage;
        }
        commonPage.setCurrentPage(Long.valueOf(page.getCurrent()).intValue());
        commonPage.setShowCount(Long.valueOf(page.getSize()).intValue());
        commonPage.setTotalResult(Long.valueOf(page.getTotal()).intValue());
        commonPage.setTotalPage(Long.valueOf(page.getPages()).intValue());
        return commonPage;
    }

    public Integer getShowCount() {
        return showCount;
    }

    public void setShowCount(Integer showCount) {
        this.showCount = showCount;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalResult() {
        return totalResult;
    }

    public void setTotalResult(Integer totalResult) {
        this.totalResult = totalResult;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }
}
